#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <unordered_map>
//找到字符串中所有的异位词：https://leetcode.cn/problems/VabMRr/
using namespace std;
class Solution {
public:
    vector<int> findAnagrams(string s, string p) {
        int count=0;
        int hash1[26]={0};
        int hash2[26]={0};
        vector<int> flag;
        int m=s.size(),n=p.size();
        for(int i=0;i<n;i++) hash1[p[i]-'a']++;
        for(int l=0,r=0;r<m;r++)
        {
            int t1=s[r]-'a';
            hash2[t1]++;
            if(hash2[t1]<=hash1[t1]) count++;
            while(r-l+1>n)
            {
                int t2=s[l++]-'a';
                if(hash2[t2]<=hash1[t2]) count--;
                hash2[t2]--;
            }
            if(count==n) 
                flag.push_back(l);
        }
        return flag;
    }
};